const multer = require('koa-multer')
const path = require('path')
// 配置
const storage = multer.diskStorage({
  // 文件保存路径
  destination: (req, file, cb) => {
    cb(null, 'public/upload')
  },
  // 修改文件名
  filename: (req, file, cb) => {
    const fileFormat = (file.originalname).split('.')
    cb(null, Date.now()+ '.'+fileFormat[fileFormat.length-1])
  }
})
// 加载配置
var upload = multer({
    storage: storage,
    limits: {
       fileSize: 1024*1024/2 // 限制512KB
     }
})

module.exports = upload